<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8" content="#">
    <title>销售订单页面</title>
    <!-- 引入CSS -->
    <link rel="stylesheet" type="text/css"
          href="/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/easyui/css/demo.css">
    <!-- 引入JS -->
    <script type="text/javascript" src="/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/easyui/themes/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/easyui/js/validateExtends.js"></script>
    <script type="text/javascript" src="/common/js/common.js"></script>
    <script type="text/javascript" src="/common/js/order.js"></script>
    <script type="text/javascript" src="/common/js/status.js"></script>
    <script type="text/javascript">
        var login_name;
        //DOM加载完成后执行的回调函数
        $(function () {
            //初始化日历控件
            $('#add_needTime').datebox({
                required: true,
                panelHeight: 'auto',
                formatter: function (date) {
                    var y = date.getFullYear();
                    var m = date.getMonth() + 1;
                    var d = date.getDate();
                    return y + '/' + m + '/' + d;
                },
                parser: function (s) {
                },
                editable: false
            });

            $('#update_needTime').datebox({
                required: true,
                panelHeight: 'auto',
                formatter: function (date) {
                    var y = date.getFullYear();
                    var m = date.getMonth() + 1;
                    var d = date.getDate();
                    return y + '/' + m + '/' + d;
                },
                parser: function (s) {
                },
                editable: false
            });

            $.post("/system/getUserName", function (data) {
                login_name = data;
            })
            var table;
            //初始化datagrid
            $('#dataList').datagrid({
                iconCls: 'icon-more',//图标
                border: true,
                collapsible: false,//是否可折叠
                fit: true,
                method: "post",
                url: "/plan-sale-order/getPlanOrderSales?t" + new Date().getTime(),
                idField: 'id',
                singleSelect: false,//是否单选
                rownumbers: true,//行号
                pagination: true,//分页控件
                remoteSort: false,
                columns: [
                    [
                        {field: 'chk', checkbox: true, width: 50},
                        {field: 'id', title: 'ID', width: 35, sortable: true},
                        {
                            field: 'status', title: '订单状态', width: 90, sortable: true,
                            formatter: function (value, row, index) {
                                return getSaleOrderStatus(value);
                            }
                        },
                        {field: 'saleOrderId', title: '订单编号', width: 120, sortable: true},
                        {field: 'saleOrderRow', title: '行号', width: 60, sortable: true},
                        {field: 'saleName', title: '销售员', width: 60, sortable: true},
                        {field: 'itemCode', title: '商品编码', width: 120, sortable: true},
                        {field: 'itemName', title: '商品名称', width: 165, sortable: true},
                        {field: 'needCnt', title: '需求量', width: 60, sortable: true},
                        {field: 'unit', title: '单位', width: 40},
                        {
                            field: 'needTime', title: '需求交期', width: 220, sortable: true,
                            formatter: function (value, row, index) {
                                return transTime(value);
                            }
                        },
                        {
                            field: 'planTime', title: '计划时间', width: 220, sortable: true,
                            formatter: function (value, row, index) {
                                return transTime(value);
                            }
                        },
                        {
                            field: 'remark', title: '备注', width: 150,
                        },
                        {field: 'clientCode', title: '客户编号', width: 70},
                        {
                            field: 'createTime', title: '创建时间', width: 220, sortable: true,
                            formatter: function (value, row, index) {
                                return transTime(value);
                            }
                        }, {
                        field: 'updateTime', title: '更新时间', width: 220, sortable: true,
                        formatter: function (value, row, index) {
                            return transTime(value);
                        }
                    }
                    ]
                ],
                toolbar: "#toolbar"//工具栏
            });

            //设置分页控件
            var p = $('#dataList').datagrid('getPager');
            $(p).pagination({
                pageSize: 10,//设置每页显示的记录条数,默认为10
                pageList: [10, 20, 30, 50, 100],//设置每页记录的条数
                beforePageText: '第',
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
            });

            //信息修改按钮事件
            $("#update").click(function () {
                var selectRows = $("#dataList").datagrid("getSelections");
                if (selectRows.length !== 1) {
                    $.messager.alert("消息提醒", "请单条选择想要修改的数据哟!", "warning");
                } else {
                    if (selectRows[0].status != 4) {
                        $.messager.alert("消息提醒", getOrderStatus(selectRows[0].status) + ",当前状态无法修改!", "warning");
                        return false;
                    }
                    $("#updateDialog").dialog("open");
                }
            });

            //设置编辑销售信息窗口
            $("#updateDialog").dialog({
                title: "修改订单信息窗口",
                width: 660,
                height: 500,
                iconCls: "icon-house",
                modal: true,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                draggable: true,
                closed: true,
                buttons: [
                    {
                        text: '提交',
                        plain: true,
                        iconCls: 'icon-update',
                        handler: function () {
                            var selectRow = $("#dataList").datagrid("getSelected");
                            var planTime = $("#update_planTime").textbox('getValue');
                            selectRow.planTime = planTime;
                            $("#updateTable").form("clear");//清空表单数据
                        }
                    }, {
                        text: '关闭',
                        plain: true,
                        iconCls: 'icon-error',
                        handler: function () {
                            $("#updateDialog").dialog("close");//关闭添加窗口
                        }
                    }
                ],
                //打开窗口前先初始化表单数据(表单回显)
                onBeforeOpen: function () {
                    var selectRow = $("#dataList").datagrid("getSelected");
                    $("#update_id").val(selectRow.id);//初始化id值,需根据id更新采购员信息
                    var planTime = transTime(selectRow.planTime);
                    $("#update_planTime").textbox('setValue', planTime);
                }
            });

            //供应链确认
            $("#plan_confirm").click(function () {
                var selectRows = $("#dataList").datagrid("getSelections");
                if (selectRows.length !== 1) {
                    $.messager.alert("消息提醒", "请单条选择想要确认的数据哟!", "warning");
                } else {
                    if (selectRows[0].status == 4) {
                        if (selectRows[0].planTime == null || selectRows[0].planTime == "") {
                            $.messager.alert("消息提醒", "计划回复交期不能为空", "warning");
                            return false;
                        }
                        var id = selectRows[0].id;
                        $.post("/plan-sale-order/updateSaleOrderStatusById", {id: id, status: 5}, function (data) {
                            if (data.success) {
                                $.messager.alert("消息提醒", "供应链确认完毕!", "info");
                                $("#dataList").datagrid("uncheckAll");//取消勾选当前页所有的行
                                $("#dataList").datagrid("reload");//刷新表格
                            } else {
                                $.messager.alert("消息提醒", "服务器端发生异常! 关闭失败!", "warning");
                            }
                        })
                    } else {
                        $.messager.alert("消息提醒", "操作失败" + getOrderStatus(selectRows[0].status), "warning");
                    }
                }
            });

            //查看Bom信息
            $("#look_bom").click(function () {
                var selectRows = $("#dataList").datagrid("getSelections");
                if (selectRows.length !== 1) {
                    $.messager.alert("消息提醒", "请单条选择想要查看的数据哟!", "warning");
                } else {
                    $("#lookBomDialog").dialog("open");
                }
            });

            $("#lookBomDialog").dialog({
                title: "查看Bom信息窗口",
                width: 800,
                height: 450,
                padding: 0,
                iconCls: "icon-house",
                modal: true,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                draggable: true,
                closed: true,
                buttons: [
                    {
                        text: '关闭',
                        plain: true,
                        iconCls: 'icon-error',
                        handler: function () {
                            $("#lookBomDialog").dialog("close");//关闭添加窗口
                        }
                    }
                ],
                //打开窗口前先初始化数据
                onBeforeOpen: function () {
                    var itemCode = $("#dataList").datagrid("getSelected").itemCode;
                    $("#lookBom_dataList").datagrid({
                        iconCls: 'icon-more',//图标
                        border: true,
                        collapsible: false,//是否可折叠
                        width: 800,
                        height: 400,
                        method: "post",
                        url: "/tech-bom/lookTechBomsByItemCode?itemCode=" + itemCode,
                        idField: 'id',
                        singleSelect: false,//是否单选
                        rownumbers: true,//行号
                        remoteSort: false,
                        columns: [
                            [
                                {field: 'chk', checkbox: true, width: 50},
                                {field: 'thingCode', title: '物料编码', width: 150, sortable: true},
                                {field: 'thingName', title: '物料描述', width: 200, sortable: true},
                                {field: 'useCnt', title: '用量', width: 50, sortable: true},
                                {field: 'unit', title: '单位', width: 50, sortable: true},
                                {field: 'remark', title: '备注', width: 100, sortable: true},
                                {field: 'price', title: '价格', width: 60},
                                {
                                    field: 'subTotal', title: '小计', width: 60,
                                    formatter: function (value, row, index) {
                                        return getBomPriceSubTotal(row);
                                    }
                                }
                            ]
                        ]
                    });
                    // //得到总价
                    // var sum = getBomTotal($("#lookBom_dataList").datagrid("getData"));
                    // alert(sum)
                    // $("#item_total").textbox('setValue', sum);
                }
            });

            //销售组名和销售名搜索按钮的监听事件(将其值返回给Controller)
            $("#search-btn").click(function () {
                var chks = $("#orderAllStatus input:checked");
                var data = "";
                for (var i = 0; i < chks.length; i++) {
                    data += chks[i].value + ",";
                }
                $('#dataList').datagrid('load', {
                    personName: $('#search-saleName').textbox('getValue'),//获取销售名称
                    personGroup: $('#search-saleGroup').combobox('getValue'),//获取销售组名称
                    orderStatus: data
                });
            });
        })
        ;
    </script>
</head>
<body>

<!-- 销售列表信息 -->
<table id="dataList" cellspacing="0" cellpadding="0"></table>

<div id="toolbar">
    <!-- 学生,班级名搜索域 -->
    <div style="margin-left: 10px;">

        <div style="float: left;"><a id="look_bom" href="javascript:" class="easyui-linkbutton"
                                     data-options="iconCls:'icon-add',plain:true">查看Bom信息</a></div>
        <div style="float: left;" class="datagrid-btn-separator"></div>

        <div style="float: left;"><a id="update" href="javascript:" class="easyui-linkbutton"
                                     data-options="iconCls:'icon-add',plain:true">更改交期</a></div>
        <div style="float: left;" class="datagrid-btn-separator"></div>

        <div style="float: left;"><a id="plan_confirm" href="javascript:" class="easyui-linkbutton"
                                     data-options="iconCls:'icon-add',plain:true">供应链确认</a></div>
        <div style="float: left;" class="datagrid-btn-separator"></div>
        <!-- 商品名称搜索框 -->
        <a href="javascript:" class="easyui-linkbutton"
           data-options="iconCls:'icon-user-student',plain:true">销售组</a>
        <select id="search-techGroup" class="easyui-combobox" style="width: 250px">
        </select>

        <a href="javascript:" class="easyui-linkbutton"
           data-options="iconCls:'icon-user-student',plain:true">订单编号</a>
        <input id="search-itemCode" class="easyui-textbox"/>

        <!-- 搜索按钮 -->
        <a id="search-btn" href="javascript:" class="easyui-linkbutton"
           data-options="iconCls:'icon-search',plain:true">搜索</a>
    </div>


</div>
<!--更新商品-->
<div id="updateDialog" style="padding: 20px 0 0 65px">
    <!-- 学生信息表单 -->
    <form id="updateForm" method="post" action="#">
        <!-- 获取被修改信息的学生id -->
        <input type="hidden" id="update_id" name="id"/>
        <table id="updateTable" style="border-collapse:separate; border-spacing:0 3px;" cellpadding="6">

            <tr>
                <td>供应链确认时间</td>
                <td colspan="4"><input id="update_planTime" style="width: 200px; height: 30px;"
                                       class="easyui-textbox"
                                       type="text"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<!--查看商品Bom-->
<div id="lookBomDialog">
    <table id="lookBom_dataList"></table>
</div>

</body>
</html>